<?php
$T->loadTpl("./html/".$template."/".$qname.".html");
$T->SetTpl('cssjs','html/cssjs.inc'); 
$T->SetTpl('jsmodel','html/jsmodel.inc');     
  
$id = isset($_GET["id"]) ? $_GET["id"] : "0";
if($id){
    $fileInfo=$T->db->query("select * from file_upload where id = ".$id)->fetch();
    $T->Set("title",$fileInfo['title']); 
    $T->Set("description",$fileInfo['description']); 
    if($fileInfo['to_id']){
        if($fileInfo['to_id']=='ALL_DEPT'){
            $fileInfo['to_id']="所有部门";
        }else{
            $fileInfo['to_id']=  rtrim($fileInfo['to_id'],",");
            $deptnames=$T->db->query("select deptname from sys_department where id in({$fileInfo['to_id']}) ")->fetchAll(PDO::FETCH_ASSOC);
            $dep='';
            foreach ($deptnames as $deptname) {
                $dep.=$deptname['deptname'].",";
            }
            $fileInfo['to_id']=  rtrim($dep,",");
        }
    }
    if($fileInfo['priv_id']){
            $fileInfo['priv_id']=  rtrim($fileInfo['priv_id'],",");
            $rolenames=$T->db->query("select rolename from sys_role where id in({$fileInfo['priv_id']}) ")->fetchAll(PDO::FETCH_ASSOC);
            $role='';
            foreach ($rolenames as $rolename) {
                $role.=$rolename['rolename'].",";
            }
            $fileInfo['priv_id']=  rtrim($role,",");
    }
    $T->Set("to_id",$fileInfo['to_id']); 
    $T->Set("priv_id",$fileInfo['priv_id']); 
    $T->Set("copy_to_id",$fileInfo['copy_to_id']); 
    if($fileInfo['attachment_name']){
        $html='';
        $fileInfo['attachment_name']=explode("*", rtrim($fileInfo['attachment_name'],"*"));
        $fileInfo['attachment_id']=explode(",", rtrim($fileInfo['attachment_id'],","));
        foreach ($fileInfo['attachment_name'] as $key => $value) {
            $path="/upload/file_fend_attachment/".$fileInfo['attachment_id'][$key]."/".$value;
            $html.="<div><a href={$path}>{$value}</a><a class='read'>阅读</a><a class='edit'>编辑</a></div>";
        }
        $fileInfo['attachment_name']=$html;
    }
    $T->Set("files",$fileInfo['attachment_name']); 
    $T->Set("uploadtime",$fileInfo['uploadtime']); 
}else{
    echo "删除有误"; exit;
}
$T->Set("template",$template);         
$T->clearNaN();       
$T->clearNoN();
$T->display(); 